<template>
	<view>
		<u-cell-group v-for="item in dataList" :key="item.id">
			<u-cell-item icon="calendar" :title="item.diskNumber" @click="toHistory(item.id)"></u-cell-item>
		</u-cell-group>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList:[],
			    pageNo: 1,
			    hasMore: true,
			    orderCount: 0,
			};
		},
		onShow() {
			this.refresh()
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			uni.showLoading({
				title: '加载中'
			})
			if (this.hasMore) {
				this.pageNo++ 
				setTimeout(() => {
					this.loadOrder({
					}).then(res => {})
					uni.hideLoading()
				}, 500)
			} else {
				setTimeout(() => {
					uni.hideLoading()
					uni.showToast({
						icon: 'none',
						title: '已经到低了哦',
						duration: 2000
					});
				}, 500)
			}
		},
		methods:{
			toHistory(id){
				this.$Router.push({ 
					name: 'choupanlistmingxi',
					params: { diskId:id},
				})
			},
			refresh(){
				this.pageNo = 1
				this.hasMore = true
				this.loadOrder({
				}).then(res => {
				})
			},
			loadOrder(param = {}) {
				return new Promise((resolve, reject) => {
					param = Object.assign(param, {
						page: this.pageNo,
						limit: 10
					})
					this.$http.post('/rest/ChouPan/apphistorydetailedList',{
					},{
						params: param,
						header: {
							'Authorization' :uni.getStorageSync('token'),
						}
					}).then(res => {
						if (this.pageNo == 1) {
							this.dataList = res.data.data
						} else {
							this.dataList = this.dataList.concat(res.data.data)
						}
						this.orderCount = res.data.count
						this.hasMore = this.pageNo * 10 < res.data.count
						resolve(res)
					})
				})
			},
		},
	}
</script>
